<?php
class Note_model extends MY_Model
{
	public
		$table = 'notes',
		$prKey = 'note_ID'
	;
	
	function __construct()
	{
		parent::__construct();

		$this->fields = array(
			'note_ID' => '',
			'note_model' => T_('Model'),
			'note_model_ID' => T_('Model ID'),
			'note_text' => T_('Message'),
			'note_user_ID' => T_('User ID'),
		);

		$this->rules = array(
			'note_model' => "trim|required|htmlspecialchars|max_length[64]",
			'note_model_ID' => "trim|required|max_length[32]",
			'note_text' => "trim|required|htmlspecialchars",
			'note_user_ID' => "trim|integer|max_length[11]",
		);
	}
	
	function getMessageList($note_model, $note_model_ID = null)
	{
		if (empty($note_model_ID))
		{
			$note_model_ID = $this->auth->getSessionKey();
		}
		
		$this->db->select('*');
		$this->db->from('notes');
		$this->db->join('users', 'note_user_ID = id', 'LEFT');
		$this->db->where('note_model', $note_model);
		$this->db->where('note_model_ID', $note_model_ID);
		$this->db->orderby('note_ID');
		
		return $this->getArray($this->db->get());
	}

	function moveMessages($from = null, $to = null, $note_model = null)
	{
		$this->db->set('note_model_ID', $to);	
		$this->db->where('note_model_ID', $from);	
		$this->db->where('note_model', $note_model);	
		$this->db->update($this->table);
	}

}
?>